/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pingouin;

import java.awt.Color;
import java.io.Serializable;

/**
 *
 * @author Hippolyte
 */
public class Pingouin implements Serializable {

    public Hexa hexa;
    public int num;
    public int nbPoissons;
    public boolean fini;
    public static final Color COLOR_PINGOUIN_SELECT = Color.DARK_GRAY;
    public static final Color COLOR_DEPLACEMENT_POSS = Color.yellow;
    public static final int RAYON = 35;

    public Pingouin(int num) {
        this.num = num;
        nbPoissons = 0;
        fini = false;
    }

    public Pingouin(Hexa hexa, int num, int nbPoissons, boolean fini) {
        this.hexa = hexa;
        this.num = num;
        this.nbPoissons = nbPoissons;
        this.fini = fini;
    }
    
    

    public boolean peutDeplacer(Hexa h) {
        if (hexa.deplacementsPossibles().contains(h)) {
//            hexa = h;
            return true;
        }
        return false;
    }
    
    public boolean deplacer(Hexa h){
        if (!peutDeplacer(h)){
            return false;
        }
//        Partie.ressources.joues.add(this.hexa);
        Partie.ressources.joues.add(h);
        
        nbPoissons+= this.hexa.nbPoisson;
        
        Partie.ressources.hexas.remove(this.hexa);
        Partie.setAllVoisinsAuto();
        
        this.hexa = h;
        Partie.ressources.deplacementOk = true;
        
        
        return true;
    }
    
    public void checkFini(){
        if(!this.fini && this.hexa.deplacementsPossibles().isEmpty()){
            Partie.ressources.joues.add(this.hexa);
        
            nbPoissons += this.hexa.nbPoisson;

            Partie.ressources.hexas.remove(this.hexa);
            Partie.setAllVoisinsAuto();
            this.fini = true;
        }
    }

    public static Pingouin getPingouinAllJoueurs(Hexa h) {
        for (Joueur j : Partie.ressources.joueurs) {
            for (Pingouin p : j.pingouins) {
                if (p.hexa.equals(h)) {
                    return p;
                }
            }
        }
        return null;
    }

    public static Pingouin getPingouin(Hexa h) {
        for (Pingouin p : Partie.ressources.JoueurEnCours.pingouins) {
            if (p.hexa.equals(h)) {
                return p;
            }
        }
        return null;
    }
    

    @Override
    public String toString() {
        return (num + " sur " + hexa.num + " : " + hexa.c1 + " , " + hexa.c2
                + " , " + hexa.c3 + " , " + hexa.c4
                + " , " + hexa.c5 + " , " + hexa.c6);
    }

    @Override
    protected Object clone() {
        Pingouin clone = new Pingouin(hexa, num, nbPoissons, fini);
        return clone;
        
    }
    
    
    
}
